/*
* $Id: Controls.h 2 2009-12-23 13:58:02Z volok-aleksej@yandex.ru $
*
* Copyright 2008-2009 by Volokitin Alexey
* All rights reserved
*
*/
#ifndef _CONTROLS_H_
#define _CONTROLS_H_

#include "Control.h"
#include "../../CommonControl.h"

interface IValidate;

class CStaticControl : public CStatic, public CControl
{
	int m_nStyle;
	std::tstring m_strType;
protected:
	virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
public:
	CStaticControl(const std::tstring& strId, const std::tstring& strState, const std::vector<Parameter>& aParameters);
	virtual ~CStaticControl();
	virtual void CreateControl(int x, int y, int cx, int cy, int nStyle, const std::tstring& strCaption, CWnd* pParent, int nId);
	virtual void SetState(const std::tstring& strState);
};

class CButtonControl : public CCommonButton, public CControl
{
	void ApplyState();
	bool m_bDownButton;
protected:
	DECLARE_MESSAGE_MAP();
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
public:
	CButtonControl(const std::tstring& strId, const std::tstring& strState, const std::vector<Parameter>& aParameters);
	virtual ~CButtonControl();
	virtual void CreateControl(int x, int y, int cx, int cy, int nStyle, const std::tstring& strCaption, CWnd* pParent, int nId);
	virtual bool IsTabStop();
	virtual void TabStop();
	virtual void SetState(const std::tstring& strState);
};

class CCheckBoxControl : public CCommonButton, public CControl
{
	virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
protected:
	DECLARE_MESSAGE_MAP();
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
public:
	CCheckBoxControl(const std::tstring& strId, const std::tstring& strState, const std::vector<Parameter>& aParameters);
	virtual ~CCheckBoxControl();
	virtual void CreateControl(int x, int y, int cx, int cy, int nStyle, const std::tstring& strCaption, CWnd* pParent, int nId);
	virtual bool IsTabStop();
	virtual void TabStop();
	virtual void SetState(const std::tstring& strState);
};

class CEditControl : public CCommonEdit, public CControl
{
protected:
	CWnd* m_pWndParent;
	std::vector<IValidate*> m_aValidate;
	void CreateParameters();
protected:
	afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
	afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
	DECLARE_MESSAGE_MAP();
public:
	CEditControl(const std::tstring& strId, const std::tstring& strState, const std::vector<Parameter>& aParameters);
	virtual ~CEditControl();

	virtual void CreateControl(int x, int y, int cx, int cy, int nStyle, const std::tstring& strCaption, CWnd* pParent, int nId);
	virtual bool IsTabStop();
	virtual void TabStop();
	virtual void SetState(const std::tstring& strState);
};

class CEditNumberControl : public CEditControl
{
protected:
	DECLARE_MESSAGE_MAP();
public:
	CEditNumberControl(const std::tstring& strId, const std::tstring& strState, const std::vector<Parameter>& aParameters);
	virtual ~CEditNumberControl();

	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
};

class CEditDoubleControl : public CEditControl
{
protected:
	afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
	DECLARE_MESSAGE_MAP();
public:
	CEditDoubleControl(const std::tstring& strId, const std::tstring& strState, const std::vector<Parameter>& aParameters);
	virtual ~CEditDoubleControl();
};

class CComboBoxControl : public CCommonCombobox, public CControl
{
protected:
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	DECLARE_MESSAGE_MAP();
	virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);
public:
	CComboBoxControl(const std::tstring& strId, const std::tstring& strState, const std::vector<Parameter>& aParameters);
	virtual ~CComboBoxControl();
	virtual void CreateControl(int x, int y, int cx, int cy, int nStyle, const std::tstring& strCaption, CWnd* pParent, int nId);
	virtual bool IsTabStop();
	virtual void TabStop();
	virtual void SetState(const std::tstring& strState);
};

class CListBoxControl : public CCommonListBox, public CControl
{
	void SaveSel(int nPos);
	void FillList();
	void AddString(const std::tstring& strValue, int nType, const std::tstring& strState);
protected:
	afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
	DECLARE_MESSAGE_MAP();
public:
	CListBoxControl(const std::tstring& strId, const std::tstring& strState, const std::vector<Parameter>& aParameters);
	virtual ~CListBoxControl();
	virtual void CreateControl(int x, int y, int cx, int cy, int nStyle, const std::tstring& strCaption, CWnd* pParent, int nId);
	virtual bool IsTabStop();
	virtual void TabStop();
	virtual void SetState(const std::tstring& strState);
};

class CDateTimeControl : public CCommonDateTimeCtrl, public CControl
{
protected:
	afx_msg void OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags);
	DECLARE_MESSAGE_MAP();
	virtual BOOL OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult);
public:
	CDateTimeControl(const std::tstring& strId, const std::tstring& strState, const std::vector<Parameter>& aParameters);
	virtual ~CDateTimeControl();
	virtual void CreateControl(int x, int y, int cx, int cy, int nStyle, const std::tstring& strCaption, CWnd* pParent, int nId);
	virtual bool IsTabStop();
	virtual void TabStop();
	virtual void SetState(const std::tstring& strState);
};

#endif /*_CONTROLS_H_*/